<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>

    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript" src="vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .el-header, .el-footer {
            background-color: #B3C0D1;
            color: #333;
            text-align: center;
            line-height: 60px;

        }
        .el-aside {
            background-color: lightgrey;
            color: #333;
            text-align: center;
            line-height: 200px;
            height: 590px;
            width: 200px;
        }

        .el-main {
            margin: 0;
            padding: 0;
        }

        body > .el-container {
            margin-bottom: 40px;
        }

        .el-container:nth-child(5) .el-aside,
        .el-container:nth-child(6) .el-aside {
            line-height: 260px;
        }

        .el-container:nth-child(7) .el-aside {
            line-height: 320px;
        }
        .el-tabs__header{
            margin: 0;
        }
    </style>

</head>
<body>

<div id="app">
    <el-container>
        <el-header>
            <el-row :gutter="20">
                <el-col :span="4"><div class="grid-content bg-purple">
                    欢迎<span v-text="userInfo.bussinessInfo.bname" style="color: red"></span>进入商家中心
                </div></el-col>
                <el-col :span="16"><div class="grid-content bg-purple">
                    <h3>菜先生商家中心</h3>
                </div></el-col>
                <el-col :span="4"><div class="grid-content bg-purple">
                    <a href="/cai/consumer/logout"><el-button icon="el-icon-switch-button" circle style="color: red;"></el-button></a>
                </div></el-col>
            </el-row>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu style="background-color: lightgrey;">
                    <el-menu-item-group>
                        <el-menu-item @click="addTep(u)" v-for="(u,i) in userPers" :index="u.id"><i :class="u.icon"></i>{{u.pname}}</el-menu-item>
                    </el-menu-item-group>
                </el-menu>
            </el-aside>
            <el-main>
                <el-tabs v-model="editableTabsValue" type="card" closable @tab-remove="removeTab">
                    <el-tab-pane
                            v-for="(item,index) in editableTabs"
                            :key="item.id"
                            :label="item.pname"
                            :name="item.id">
                        <iframe :src="item.url" width="100% " height="600" style="border: 0;"></iframe>
                    </el-tab-pane>
                </el-tabs>
            </el-main>
        </el-container>
    </el-container>
</div>
<script>
    //获取权限信息
    $.get("/cai/consumer/getInfo",function (backData) {
        app.userInfo= backData.data.userInfo;
        app.userPers = backData.data.userPers;
    });
    var app = new Vue({
        el: "#app",
        data: {
            userInfo:{},
            userPers:[],
            editableTabs:[
                {"id":0,"pname":"欢迎页","url":"/cai/hello.html"}
            ],
            editableTabsValue:"0"
        },
        methods: {
            addTep:function(a){
                if(app.editableTabs.indexOf(a)<0){
                    app.editableTabs.push(a);
                }
                app.editableTabsValue = a.id;
            },
            removeTab(targetName) {
                let tabs = app.editableTabs;
                let activeName = app.editableTabsValue;
                if (activeName === targetName) {
                    tabs.forEach((tab, index) => {
                        if (tab.id === targetName) {
                            let nextTab = tabs[index + 1] || tabs[index - 1];
                            if (nextTab) {
                                activeName = nextTab.id;
                            }
                        }
                    });
                }
                app.editableTabsValue = activeName;
                app.editableTabs = tabs.filter(tab => tab.id !== targetName);
            }
        }
    });
</script>


</body>
</html>
